package com.ys.controller.api.mall;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bo.vo.R;
import com.ys.entity.mall.TmCate;
import com.ys.service.mall.TmCateService;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.LayuiTableVoJA;

@Controller
@RequestMapping("/api/inter/tmCate")
public class ApiInterTmCateController {
	@Autowired
	private CommonApiService<TmCate> commonApiService;
	@Autowired
	private TmCateService tmCateService;

	@RequiresPermissions("tmCate:view")
	@RequestMapping("/search")
	@ResponseBody
	public LayuiTableVoJA search(@ModelAttribute TmCate cond){
		cond.setOrderby("A.SortNo asc");
		return commonApiService.searchLay(cond);
	}
	
	
	/**
	 * 新增
	 */
	@RequiresPermissions("tmCate:add")
	@PostMapping("/add")
    @ResponseBody
	public R add(HttpServletRequest request, @RequestParam Map<String, Object> params){

		return tmCateService.add(params);
	}
	
	/**
	 * 修改
	 */
	@RequiresPermissions("tmCate:edit")
	@PostMapping("/edit")
    @ResponseBody
	public R edit(@RequestParam Map<String, Object> params){
		try {
			return tmCateService.edit(params);
		} catch (Exception e) {
			e.printStackTrace();
			return R.error("系统正在开小差，请联系客服，我们将第一时间为您解决！");
		}

	}
	
	/**
	 * 置顶
	 */
	@PostMapping("/moveTop")
    @ResponseBody
	public R moveTop(Long id){
		try {
			return tmCateService.moveTop(id);
		} catch (Exception e) {
			e.printStackTrace();
			return R.error("系统正在开小差，请联系客服，我们将第一时间为您解决！");
		}

	}
	
	/**
	 * 调整顺序
	 */
	@RequiresPermissions("tmCate:resort")
	@PostMapping("/resort")
    @ResponseBody
	public R resort(String rows){
		return tmCateService.resort(rows);
	}
}